<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>队列</title>
</head>
<body>
  <script>
    function Queue(){
      var items = [];

      this.enqueue = function(element){
        items.push(element);
      };
      this.dequeue = function(){
        return items.shift();
      };
      this.front = function(){
        return items.shirft[0];
      };
      this.isEmpty = function(){
        return items.length == 0;
      };
      this.clear = function(){
        items = [];
      };
      this.size = function(){
        return items.length;
      };
      this.print = function(){
        console.log(items.toString());
      };
    }
    function hotPotato (nameList, num){
      var queue = new Queue();

      for (var i = 0; i < nameList.length; i++){
        queue.enqueue(nameList[i]);
      }

      var eliminated = '';

      while (queue.size() > 1){
        for (var i = 0; i < num; i++){
          queue.enqueue(queue.dequeue());//形成循环，将首位放置末位，依次循环。
        }
        eliminated = queue.dequeue();
        console.log(eliminated + '在游戏中淘汰');
      }
      return queue.dequeue();
    }
    var names = ['Jonn','Javcj','ming','sasdk','yang'];
    var winner = hotPotato(names, 7);
    console.log('胜利者:' + winner);

  </script>
</body>

</html>